package com.gylang.print.pdf.domain.component.text;

import com.gylang.easy.lazy.FunBuilder;
import com.gylang.print.pdf.domain.PdfPageWrapper;
import com.gylang.print.pdf.domain.component.BasePdfComponent;
import com.gylang.print.pdf.enums.OverFlowEnums;
import com.gylang.print.pdf.enums.PdfComponentEnums;
import com.gylang.print.pdf.util.PdfUtil;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.pdfbox.pdmodel.font.PDFont;

import java.awt.*;
import java.util.Collections;
import java.util.List;

/**
 * 文本field
 *
 * @author gylang
 * data 2021/6/4
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
public class TextPdfComponent extends BasePdfComponent implements FunBuilder<TextPdfComponent> {

	/**
	 * 可以自己加载字体库
	 */
	public static final String DEFAULT_FONT = "STSONG.TTF";

	/** 文本内容 */
	private String content;


	private List<String> multiLine;


	// 样式  -------------------------------------------------------------------------------



	/** 颜色 */
	private Color color = Color.black;

	/** 换行 */
	private boolean br;

	/** 字体 */
	private PDFont font;

	/** 大小 */
	private float size = 14;

	/** 间距 cs.appendRawCommands("0.25 Tc\n"); */
	private float interval;
	/** 行间距 */
	@Builder.Default
	private float brInterval = 1F;

	/** 文本溢出 */
	@Builder.Default
	private OverFlowEnums overFlow = OverFlowEnums.NONE;

	/** x轴左边框 */
	private float borderLeftX;

	/** x轴右边框 */
	private float borderRightX;

	/** y轴顶部边框 */
	private float borderTopY;

	/** y轴底部边框 */
	private float borderBottomY;

	// 位置 -------------------------------------------------------------------------------


	/** 方向 0水平 1垂直 */
	private int direct;



	public List<String> getMultiLine() {

		if (null == multiLine) {
			if (!isBr()) {
				return multiLine = Collections.singletonList(content);
			}
			multiLine = PdfUtil.splitLines(this);
		}
		return multiLine;
	}

	public TextPdfComponent() {
		super(PdfComponentEnums.TEXT.getType());
	}

	public TextPdfComponent(PdfPageWrapper pageWrapper) {
		super(PdfComponentEnums.TEXT.getType());
		this.pageWrapper = pageWrapper;
	}


}
